<?php

namespace App\Models\Traits;

use Carbon\Carbon;
use App\Models\GoldRecord;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;

trait HasUserOrderPendingCache
{
	public function pendingOrdersCacheKey(): string
	{
		return "user_{$this->id}_pending_orders";
	}

	public function addOrderToPendingCache($cacheId)
	{
		Redis::zAdd($this->pendingOrdersCacheKey(), 1, $cacheId);
	}

	public function delOrderFromPendingCache($cacheId)
	{
		Redis::zRem($this->pendingOrdersCacheKey(), $cacheId);
	}

	public function isOrderInPendingCache($cacheId): bool
	{
		return Redis::zScore($this->pendingOrdersCacheKey(), $cacheId) == 1;
	}
}
